/*
 * Date         Author      Note
 * 2015.04.30   wzwz        报警屏蔽
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <mh/common.h>
#include <mh/sram.h>
#include <mh/mac.h>
#include "knit.h"
#include <mh/mh_file.h>
#include <mh/probe.h>
#include <sys/stat.h>

/*
 *

 */
int GetAlarmMask(MH_KNIT *p)
{
    int ret = 0;
    if(1)//(p->company == COMPANY_HQ)
    {
        ret = p->alarm_mask;
    }
    else
    {
        union
        {
            ALARM_MASK mask;
            int all;
        } alarm;
        alarm.mask.back_probe = 0;
        alarm.mask.front_probe = 0;
        alarm.mask.right_drt = 1;
        alarm.mask.left_drt = 1;
        alarm.mask.board = !p->board_enable;
        alarm.mask.has_roll = 1;//low roller
//        alarm.mask.ac110 = 0;
        alarm.mask.board_zero = 1;
        alarm.mask.knot = 0;
        alarm.mask.balcony = 0;
        alarm.mask.left_break = 0;
        alarm.mask.right_break = 0;
        alarm.mask.front_safe_door = !p->front_safe_door_enable;
        alarm.mask.back_safe_door = !p->back_safe_door_enable;
        alarm.mask.rab = 0; //高罗拉
        alarm.mask.roll = 1; //低罗拉(主拉布)
        alarm.mask.fender = 1;
        alarm.mask.left_rubber = 1;
        alarm.mask.right_back_safe_door = !p->back_safe_door_enable;
        alarm.mask.drop_bad = 1;
        alarm.mask.board_high = 1;
        alarm.mask.scram = 1;
        alarm.mask.fender = 1;
        alarm.mask.left_feeder = 1;
        alarm.mask.right_feeder = 1;
        alarm.mask.storage = 1;

        ret = alarm.all;
    }
    return ret;
}
/*
 *
 */
void SetAlarmMask(MH_KNIT *p, int mask)
{
    p->alarm_mask = mask;
}
/*
 *
 */
void SetLeftFeederAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->left_feeder = !valid;
}
/*
 *
 */
void SetRightFeederAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->right_feeder = !valid;
}
/*
 *
 */
void SetLeftBreakAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->left_break = !valid;
}
/*
 *
 */
void SetRightBreakAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->right_break = !valid;
}
/*
 *
 */
void SetBalconyAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->balcony = !valid;
}
/*
 *
 */
void SetKnotAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->knot = !valid;
}
/*
 *
 */
void SetRabAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->rab = !valid;
}
/*
 *
 */
void SetRollAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->roll = !valid;
}
/*
 *
 */
void SetStorageAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->storage = !valid;
}
/*
 *
 */
void SetMacHasRoll(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->has_roll = !valid;
}
/*
 *
 */
void SetFrontProbeAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->front_probe = !valid;
}
/*
 *
 */
void SetBackProbeAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->back_probe = !valid;
}
/*
 *
 */
void SetLeftDrtAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->left_drt = !valid;
}
/*
 *
 */
void SetRightDrtAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->right_drt = !valid;
}
/*
 *
 */
void SetScramAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->scram = !valid;
}
/*
 *
 */
void SetAC110Alarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->ac110 = !valid;
}
/*
 *
 */
void SetBackSafeDoorAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->back_safe_door = !valid;
}
/*
 *
 */
void SetRightBackSafeDoorAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->right_back_safe_door = !valid;
}
/*
 *
 */
void SetFrontSafeDoorAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->front_safe_door = !valid;
}
/*
 *
 */
void SetLeftRubberAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->left_rubber = !valid;
}
/*
 *
 */
void SetBoardAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->board = !valid;
}
/*
 *
 */
void SetFenderAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->fender = !valid;
}
/*
 *
 */
void SetBoardZeroAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->board_zero = !valid;
}
/*
 *
 */
void SetBoardHighAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->board_high = !valid;
}
/*
 *
 */
void SetDropBadAlarm(MH_KNIT *p, int valid)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->drop_bad = !valid;
}
/*
 *
 */
int SwitchLeftFeederAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->left_feeder = !palarm->left_feeder;
    return palarm->left_feeder;
}
/*
 *
 */
int SwitchRightFeederAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->right_feeder = !palarm->right_feeder;
    return palarm->right_feeder;
}
/*
 *
 */
int SwitchLeftBreakAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->left_break = !palarm->left_break;
    return palarm->left_break;
}
/*
 *
 */
int SwitchRightBreakAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->right_break = !palarm->right_break;
    return palarm->right_break;
}
/*
 *
 */
int SwitchBalconyAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->balcony = !palarm->balcony;
    return palarm->balcony;
}
/*
 *
 */
int SwitchKnotAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->knot = !palarm->knot;
    return palarm->knot;
}
/*
 *
 */
int SwitchRabAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->rab = !palarm->rab;
    return palarm->rab;
}
/*
 *
 */
int SwitchRollAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->roll = !palarm->roll;
    return palarm->roll;
}
/*
 *
 */
int SwitchStorageAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->storage = !palarm->storage;
    return palarm->storage;
}
/*
 *
 */
int SwitchMacHasRoll(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->has_roll = !palarm->has_roll;
    return palarm->has_roll;
}
/*
 *
 */
int SwitchFrontProbeAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->front_probe = !palarm->front_probe;
    return palarm->front_probe;
}
/*
 *
 */
int SwitchBackProbeAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->back_probe = !palarm->back_probe;
    return palarm->back_probe;
}
/*
 *
 */
int SwitchLeftDrtAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->left_drt = !palarm->left_drt;
    return palarm->left_drt;
}
/*
 *
 */
int SwitchRightDrtAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->right_drt = !palarm->right_drt;
    return palarm->right_drt;
}
/*
 *
 */
int SwitchScramAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->scram = !palarm->scram;
    return palarm->scram;
}
/*
 *
 */
int SwitchAC110Alarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->ac110 = !palarm->ac110;
    return palarm->ac110;
}
/*
 *
 */
int SwitchBackSafeDoorAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->back_safe_door = !palarm->back_safe_door;
    return palarm->back_safe_door;
}
/*
 *
 */
int SwitchRightBackSafeDoorAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->right_back_safe_door = !palarm->right_back_safe_door;
    return palarm->right_back_safe_door;
}
/*
 *
 */
int SwitchFrontSafeDoorAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->front_safe_door = !palarm->front_safe_door;
    return palarm->front_safe_door;
}
/*
 *
 */
int SwitchLeftRubberAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->left_rubber = !palarm->left_rubber;
    return palarm->left_rubber;
}
/*
 *
 */
int SwitchBoardAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->board = !palarm->board;
    return palarm->board;
}
/*
 *
 */
int SwitchFenderAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->fender = !palarm->fender;
    return palarm->fender;
}
/*
 *
 */
int SwitchBoardZeroAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->board_zero = !palarm->board_zero;
    return palarm->board_zero;
}
/*
 *
 */
int SwitchBoardHighAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->board_high = !palarm->board_high;
    return palarm->board_high;
}
/*
 *
 */
int SwitchDropBadAlarm(MH_KNIT *p)
{
    ALARM_MASK *palarm = (ALARM_MASK *)&p->alarm_mask;
    palarm->drop_bad = !palarm->drop_bad;
    return palarm->drop_bad;
}
